package com.ruoyi.recommend.controller;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recommend.domain.Picture;
import com.ruoyi.recommend.service.IPictureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 图片管理Controller
 *
 * @author wwh
 * @date 2023-07-23
 */
@RestController
@RequestMapping("/recommend/picture")
public class PictureController extends BaseController {
    @Autowired
    private IPictureService IPictureService;

    /**
     * 查询图片管理列表
     */
    @PreAuthorize("@ss.hasPermi('picture:picture:list')")
    @GetMapping("/list")
    public TableDataInfo list(Picture picture) {
        startPage();
        List<Picture> list = IPictureService.selectPictureList(picture);
        return getDataTable(list);
    }

    /**
     * 导出图片管理列表
     */
    @PreAuthorize("@ss.hasPermi('picture:picture:export')")
    @Log(title = "图片管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Picture picture) {
        List<Picture> list = IPictureService.selectPictureList(picture);
        ExcelUtil<Picture> util = new ExcelUtil<Picture>(Picture.class);
        util.exportExcel(response, list, "图片管理数据");
    }

    /**
     * 获取图片管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('picture:picture:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(IPictureService.selectPictureById(id));
    }

    /**
     * 新增图片管理
     */
    @PreAuthorize("@ss.hasPermi('picture:picture:add')")
    @Log(title = "图片管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Picture picture) {
        picture.setCreateBy(super.getUsername());
        picture.setUpdateBy(super.getUsername());
        return toAjax(IPictureService.insertPicture(picture));
    }

    /**
     * 修改图片管理
     */
    @PreAuthorize("@ss.hasPermi('picture:picture:edit')")
    @Log(title = "图片管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Picture picture) {
        picture.setUpdateBy(super.getUsername());
        return toAjax(IPictureService.updatePicture(picture));
    }

    /**
     * 删除图片管理
     */
    @PreAuthorize("@ss.hasPermi('picture:picture:remove')")
    @Log(title = "图片管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(IPictureService.deletePictureByIds(ids));
    }



}
